<template>
  <div>
    <search v-model="newsParam.keyWord" @on-submit="onSearch"></search>
    <x-table>
      <tr v-for="_new in news">
        <td style="text-align: left;">{{ _new.TITLE }}</td>
      </tr>
    </x-table>
    <router-link :to="{ name:'HelloWorld' }">HelloWorld</router-link><br/>
    <router-link :to="{ name:'Form' }">Form</router-link><br/>
    <router-link :to="{ name:'TestPage' }">TestPage</router-link>
  </div>
</template>

<script>
  import * as config from '../config/index'
  import { Search, XTable } from 'vux'

  export default {
    components: {
      Search,
      XTable
    },
    name: 'Index',
    data () {
      return {
        newsParam: {
          curPageNum: 1,
          pageCount: 10,
          keyWord : ''
        },
        news : null
      }
    },
    methods: {
      onSearch () {
        this.$http.post(config.rootpath + '/app/news/eCardNews', this.newsParam).then((response) => {
          // 响应成功回调
          var body = response.body
          if (body.code === 0) {
            this.news = body.data
          } else {
            this.showToast(body.message)
          }
        }, (response) => {
          // 响应错误回调
          this.showToast('请求错误')
        })
      },
      showToast (text) {
        this.$store.commit('showToast', text)
      }
    }
  }
</script>

<style scoped>

</style>
